"use strict";
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var os_1 = __importDefault(require("os"));
var chalk_1 = require("chalk");
var ClientPlugin = /** @class */ (function () {
    function ClientPlugin() {
    }
    ClientPlugin.prototype.apply = function (compiler) {
        compiler.hooks.done.tap('ClientPlugin', function (stats) {
            var e_1, _a, e_2, _b;
            var _c = stats.compilation.options.devServer, _d = _c.port, port = _d === void 0 ? 8080 : _d, _e = _c.server, server = _e === void 0 ? {} : _e;
            var networkInterfaces = os_1.default.networkInterfaces();
            var protocol = "http";
            var hostnameName;
            if (Object.prototype.toString.call(server) === "[object String]") {
                if (server && server.toLowerCase() == "https") {
                    protocol = "https";
                }
            }
            else {
                if (server.type && server.type.toLowerCase() == "https") {
                    protocol = "https";
                }
            }
            try {
                for (var _f = __values(Object.values(networkInterfaces)), _g = _f.next(); !_g.done; _g = _f.next()) {
                    var iface = _g.value;
                    if (iface) {
                        try {
                            for (var iface_1 = (e_2 = void 0, __values(iface)), iface_1_1 = iface_1.next(); !iface_1_1.done; iface_1_1 = iface_1.next()) {
                                var config = iface_1_1.value;
                                if (config.family === 'IPv4' && !config.internal) {
                                    hostnameName = config.address;
                                }
                            }
                        }
                        catch (e_2_1) { e_2 = { error: e_2_1 }; }
                        finally {
                            try {
                                if (iface_1_1 && !iface_1_1.done && (_b = iface_1.return)) _b.call(iface_1);
                            }
                            finally { if (e_2) throw e_2.error; }
                        }
                    }
                }
            }
            catch (e_1_1) { e_1 = { error: e_1_1 }; }
            finally {
                try {
                    if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
                }
                finally { if (e_1) throw e_1.error; }
            }
            if (hostnameName) {
                console.log("".concat((0, chalk_1.bold)((0, chalk_1.green)("\u279C Local: "))).concat((0, chalk_1.cyan)("".concat(protocol, "://localhost:").concat(port))));
                console.log("".concat((0, chalk_1.bold)((0, chalk_1.green)("\u279C Network: "))).concat((0, chalk_1.cyan)("".concat(protocol, "://").concat(hostnameName, ":").concat(port, "\n"))));
            }
            else {
                console.log("".concat((0, chalk_1.bold)((0, chalk_1.green)("\u279C Local: "))).concat((0, chalk_1.cyan)("".concat(protocol, "://localhost:").concat(port)), "\n"));
            }
        });
    };
    return ClientPlugin;
}());
exports.default = ClientPlugin;
